<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">

<head>
<meta charset="UTF-8">
<title>秘钥配置</title>

<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-table.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/style.css">
<link rel="stylesheet" type="text/css"
	href="bootstrap/css/bootstrap-editable.css">
<link rel="stylesheet" type="text/css" href="bootstrap/css/dropzone.css">

</head>

<body>
	<div th:insert="~{header :: copy}"></div>

	<div class="panel panel-default" style="padding-top: 80px;margin-left: 50px;margin-right: 50px;border: 0px">
		<div class="panel-heading" style="background: white;">
			<font size="5px">秘钥配置</font>
		</div>
		<div class="panel-body">
			<div id="toolbar" class="btn-group">
				<button id="btn_add" type="button" class="btn btn-default"
					data-toggle="modal" data-target="#addModel">
					<span class="glyphicon glyphicon-plus" aria-hidden="true"></span>新增
				</button>
			</div>
			<table id="table"></table>
		</div>
	</div>

	<div id="addModel" class="modal fade" tabindex="-1" role="dialog"
		aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog modal-lg">
			<div class="modal-content" style="width: 500px; align-self: center;">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-hidden="true"></button>
					<h4 class="modal-title">
						<i class="icon-pencil"></i> <span id="lblAddTitle"
							style="font-weight: bold">添加秘钥配置</span>
					</h4>
				</div>
				<div class="modal-body" style="text-align: center;">
					<form id='searchForm' action="apiDefine/saveOrUpdate"
						class="bs-example bs-example-form" role="form"
						style="align-self: center;">
						<div class="input-group">
							<span class="input-group-addon" style="width: 150px">
								<i class="icon-th">商户编号</i>
							</span>
							<input type="text" class="form-control"
								name="partnerCode" id="secretInfo-partnerCode" onblur="validateEmptyContent('secretInfo-partnerCode','partnerCodeMsgSpan')">
							<span class="input-group-addon" id="partnerCodeMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 150px"><i
								class="icon-th">硬件加密IP</i></span> <input type="text"
								class=" form-control" name="encryptHardwareIp" id="secretInfo-encryptHardwareIp" placeholder="127.0.0.1">
							<span class="input-group-addon" id="encryptHardwareIpMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 150px"><i
								class="icon-th">私钥路径</i></span> <input type="text"
								class=" form-control" name="privateKeyPath" id="secretInfo-privateKeyPath">
							<span class="input-group-addon" id="privateKeyPathMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 150px"><i
								class="icon-th">公钥路径</i></span> <input type="text"
								class=" form-control" name="publicKeyPath" id="secretInfo-publicKeyPath">
							<span class="input-group-addon" id="publicKeyPathMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 150px"><i
								class="icon-th">硬件加密端口</i></span> <input type="text"
								class=" form-control" name="encryptHardwarePort"
								id="secretInfo-encryptHardwarePort" placeholder="1025~65534">
							<span class="input-group-addon" id="encryptHardwarePortMsgSpan" style="width: 150px;border:1px; background:#FFF"></span>
						</div>
						<div class="input-group">
							<span class="input-group-addon" style="width: 150px"><i
								class="icon-th">加密类型</i></span> 
							<select id="secretInfo-encryptType" style="height: 28px"></select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 150px"><i
								class="icon-th">是否硬件加密</i></span>
							<select style="height: 28px" name = "isEncryptHardware" id="secretInfo-isEncryptHardware">
								<option value="1">是</option>
								<option value="0" selected="selected">否</option>
							</select>
						</div>
						<div class="input-group">
							<span class="input-group-addon text-center" style="width: 150px"><i
								class="icon-th">是否激活</i></span> 
							<select style="height: 28px" name = "isActivated" id="secretInfo-isActivated">
								<option value="1">是</option>
								<option value="0" selected="selected">否</option>
							</select>
						</div>
					</form>
				</div>
				<div class="modal-footer">
					<input type="hidden" id="ID" name="ID" />
					<button type="submit" class="btn btn-primary"
						onclick="saveSecretInfo()" data-dismiss="modal">确定</button>
					<button type="button" class="btn green" data-dismiss="modal">取消</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="bootstrap/js/jquery.min.js"></script>
<script src="bootstrap/js/jquery-ui.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
<script src="bootstrap/js/bootstrap-table.js"></script>
<script src="bootstrap/js/bootstrap-editable.min.js"></script>
<script src="bootstrap/js/dropzone.js"></script>
<script src="bootstrap/js/bootstrap-table-editable.js"></script>
<script src="bootstrap/js/gateway.js"></script>
<script type="text/javascript">
	function saveSecretInfo() {
		var partnerCode = $("#secretInfo-partnerCode").val();
		var encryptType = $("#secretInfo-encryptType").val();
		var isEncryptHardware = $("#secretInfo-isEncryptHardware").val();
		var encryptHardwareIp = $("#secretInfo-encryptHardwareIp").val();
		var privateKeyPath = $("#secretInfo-privateKeyPath").val();
		var publicKeyPath = $("#secretInfo-publicKeyPath").val();
		var isActivated = $('#secretInfo-isActivated').val();
		var encryptHardwarePort = $("#secretInfo-encryptHardwarePort").val();
		
		
		var data = {
			partnerCode : partnerCode,
			encryptType : encryptType,
			isEncryptHardware : isEncryptHardware,
			encryptHardwareIp : encryptHardwareIp,
			privateKeyPath : privateKeyPath,
			publicKeyPath : publicKeyPath,
			isActivated : isActivated,
			encryptHardwarePort : encryptHardwarePort
		}
		
		saveOrUpdateGateWayConfigurations(data, "/secretInfo/saveOrUpdate", "add");

	}
</script>
<script type="text/javascript">
	$(function() {
		$("#addModel").draggable();//为模态对话框添加拖拽

		var encryptTypeArray = new Array();
		
		//加载加密类型
		$.ajax({
			type:"get",
			url:"/constants/getEncryptTypes",
			async : false,
			success : function(data) {
				var types = "";
				for(var i = 0; i < data.length; i++ ) {
					encryptTypeArray[i] = {value:data[i], text:data[i]};
					types += "<option value='"+ data[i] +"'>" + data[i] +"</option>";
				}
				$("#secretInfo-encryptType").append(types);
			},
			error : function() {
				alert("加密类型加载失败!");
			}
		});
		
		var curRow = {};
		$('#table').bootstrapTable({
			url : '/secretInfo/listAll',
			pagination : true,
			pageSize : 10,
			pageNumber : 1,
			search : true,
			searchAlign : "right",
			toolbar : "#toolbar",
			checkboxHeader:false,
			columns : [ {
				field : 'id',
				title : 'id'
			}, {
				field : 'partnerCode',
				title : '商户编号',
				editable : {
					type : 'text',
					title : '商户编号',
					validate : function(v) {
						if (!v)
							return '商户编号不能为空';

					}
				}
			}, {
				field : 'encryptType',
				title : '加密类型',
				editable : {
                    type: 'select',
                    title: '加密类型',
                    source: encryptTypeArray
				}
			}, {
				field : 'isEncryptHardware',
				title : '是否硬件加密',
				editable : {
                    type: 'select',
                    title: '是否硬件加密',
                    source:[{value:"1",text:"是"},{value:"0",text:"否"}]
				}
			}, {
				field : 'encryptHardwareIp',
				title : '硬件加密IP',
				editable : {
					type : 'text',
					title : '硬件加密IP'
				}
			}, {
				field : 'privateKeyPath',
				title : '私钥路径',
				editable : {
					type : 'text',
					title : '私钥路径'
				}
			}, {
				field : 'publicKeyPath',
				title : '公钥路径',
				editable : {
					type : 'text',
					title : '公钥路径'
				}
			}, {
				field : 'isActivated',
				title : '是否激活',
				editable : {
                    type: 'select',
                    title: '是否激活',
                    source:[{value:"1",text:"是"},{value:"0",text:"否"}]
				}
			}, {
				field : 'encryptHardwarePort',
				title : '硬件加密端口',
				editable : {
					type : 'text',
					title : '硬件加密端口'
				}
			}, {
				field : 'formatCreateTime',
				title : '创建时间',
			}, {
				field : 'formatUpdateTime',
				title : '修改时间',
			}],
			onClickRow : function(row, $element) {
				curRow = row;
			},
			onEditableSave : function(field, row, oldValue, $el) {
				var data = {
					id : row.id,
					partnerCode : row.partnerCode,
					encryptType : row.encryptType,
					isEncryptHardware : row.isEncryptHardware,
					encryptHardwareIp : row.encryptHardwareIp,
					privateKeyPath : row.privateKeyPath,
					publicKeyPath : row.publicKeyPath,
					isActivated : row.isActivated,
					encryptHardwarePort : row.encryptHardwarePort	
				}
				saveOrUpdateGateWayConfigurations(data, "/secretInfo/saveOrUpdate", "update");
			}
		});
	});
</script>

</html>